﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TravelGenerator.WebApplication.Models;
using TravelGenerator.WebApplication.Tools;
using TravelGenerator.BusinessObjects.ModelObjects;
using System.Security.Cryptography;
using System.Web.Routing;

namespace TravelGenerator.WebApplication.Controllers
{
    public class AccountController : Controller
    {
        public IFormsAuthenticationService FormsService { get; set; }        

        protected override void Initialize(RequestContext requestContext)
        {
            if (FormsService == null) { FormsService = new FormsAuthenticationService(); }            

            base.Initialize(requestContext);
        }

        //
        // GET: /Account/
        public ActionResult Index()
        {
            return View();
        }

        // **************************************
        // URL: /Account/LogOn
        // **************************************

        public ActionResult LogOn()
        {
            return View();
        }

        [HttpPost]
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                Contact contact = null;// ServiceManager.IAccountManagement.AuthenticateAccount(model.UserName, model.Password);

                if (contact != null)
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }

        // **************************************
        // URL: /Account/LogOff
        // **************************************

        public ActionResult LogOff()
        {
            return View();
        }

        

    }
}
